
#pragma once

#include <string>
#include "formation.h"

class Unit;

class Army {

public:
	Army();
	~Army();

	void update(float ticks);
	void updateFormationState();
	void removeUnitsTarget(Unit *unit);
	void march(float contactPosition);

	void moveSquad(int squadIndex, float distance);

	Unit* getSoldier(int id);
	Unit* getSoldier(int line, int row) {
		int id = gridsState[line][row];
		return getSoldier(id);
	}

	Unit* getSoldierForAssign(int line, int row);

	Unit* getFrontLineSoldier(int id);

	int getLineSoldierCount(int globalLineIndex);
	float getFrontLineTargetPosition();

	void getFrontUnits(GridInfo info, vector<Unit*> &arr);
	void getFrontLineUnits(vector<Unit*> &arr);
	void getFrontSquadUnits(vector<Unit*> &arr);
	void getSquadUnits(int squadIndex, vector<Unit*> &arr);
	void getAllUnits(vector<Unit*> &arr);
	void getAroundUnits(const CCPoint& pos, vector<Unit*> &arr);

	bool isFrontSquadStandby();
	bool isFrontSquadAllDied();

	void updateGridsState(Unit *unit, int line, int row);
	void updatePositionTable(Unit *unit, int line, int row);
	void releaseUnitOccupiedGrids(Unit* unit);
	void releaseUnitAssignedPosition(Unit *unit);

	bool testGridForAssigningUnit(Unit *unit, int line, int row);
	bool testGridForMovingUnit(Unit *unit, int line, int row);

public:
	SquadOrder orders[SQUAD_COUNT];

	Unit* soldiers[TOTAL_LINES][ROWS_PER_LINE];

	int gridsState[TOTAL_LINES][ROWS_PER_LINE];
	int positionTable[TOTAL_LINES][ROWS_PER_LINE];

	int frontLine;
	int frontLineIndex;

	float frontLinePosition;

	int deaths;
	int arrivals;
	int idles;

	ArmyFaction faction;
};